/* eslint valid-jsdoc: 'off' */
const path = require("path");
const os = require("os");

const jwt = {
  secret: "qiyejia_server",
};

const cors = {
  origin: "*",
  credential: true,
  allowMethods: "GET, PUT, POST, DELETE, PATCH",
};

const isLinuxEnvironment = require("os").platform() === "linux";

if (isLinuxEnvironment) {
  host = "mysql";
  username = "root";
  password = "91vDQhMgF9wzZlYf/MTUiZzAebT9D8Yi";
} else {
  host = "localhost";
  username = "wjffff";
  password = "wjffff";
}

const mysqlConfig = {
  host,
  port: 3306,
  username,
  password,
};
const schedule = {
  tasks: {
    cleanupExpiredTokens: {
      //   schedule: '0 2 * * *', // 这里可以省略，因为已经在任务类中定义
    },
  },
};

const logger = {
  level: "INFO",
  type: "dateFile",
  console: true,
  disableConsoleAfterReady: false,
  output: "both",
};

const security = {
  csrf: {
    enable: false,
  },
};

const middleware = ['error'];

const multipart = {
  mode: "file",
  tmpdir: path.join(os.tmpdir(), "egg-multipart-tmp"),
  fileSize: "100mb", // 设置文件大小限制，例如100MB
  cleanSchedule: {
    cron: "0 30 4 * * *",
    disable: false,
  },
  fileExtensions: [".m3u8", ".ts", ".txt", ".docx", ".doc", ".csv"],
  allowArrayField: true,
};

const session = {
    key: 'session',
    maxAge: 2 * 60 * 60 * 1000,
    httpOnly: true,
    encrypt: true
}

module.exports = (appInfo) => {
  const config = (exports = {});

  const data = {
    keys: appInfo.name + "_1716451288095_8483",
    middleware,
    jwt,
    cors,
    schedule,
    security,
    logger,
    multipart,
    session,
    sequelize: {
      dialect: "mysql",
      ...mysqlConfig,
      timezone: "+08:00",
      database: "server",
      define: {
        // 使用自定义的表名
        freezeTableName: true,
        // 自动生成时间戳 -小驼峰式
        timestamps: true,
        // 表名小驼峰
        underscored: false,
      },
    },
  };

  return {
    ...config,
    ...data,
  };
};
